﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 解释器模式
{

    /// <summary>
    /// 中国人的解释器
    /// </summary>
    class Chinese : PeopleInterpreter
    {
        private Dictionary<char, string> dic = new Dictionary<char, string>();

        public Chinese()
        {
            dic.Add('c',"中国人");
            dic.Add('h',"用");
            dic.Add('i',"筷子吃饭");
        }
        public override void Conversion(Context context)
        {
            Console.WriteLine(this.GetType().ToString()+"业务");
            string text = context.Get();
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            List<string> strList = new List<string>();
            foreach(var item in text.ToLower().ToCharArray())
            {
                if (dic.ContainsKey(item))
                {
                    strList.Add(dic[item]);
                }
                else
                {
                    strList.Add(item.ToString());
                }
            }
            context.Set(string.Concat(strList)); ;
        }
    }
}
